<?php if(!defined('WDK_PATH')) exit('No direct script access allowed');
/**
 * @since 2011. 9. 30
 * @author kinuz
 */
class Hp_Email implements ArrayAccess
{
	private static $smtp = null;
	//--------------------------------------------------------------------------------------------//
	//	functions to implemet for ArrayAccess
	//--------------------------------------------------------------------------------------------//
	public final function offsetSet($offset, $value) {$this->{$offset} = $value;}
	public final function offsetExists($offset) {return isset($this->{$offset});}
	public final function offsetUnset($offset) {unset($this->{$offset});}
	public final function offsetGet($offset) {return isset($this->{$offset}) ? $this->{$offset} : null;}
	//--------------------------------------------------------------------------------------------//
	
	protected	
		$from		=	"",
		$to			=	array(),
		$subject	=	'',
		$body		=	'';
	
	/**
	 * 	생성자
	 * @since 2011. 9. 30
	 * @author kinuz
	 */
	function __construct()
	{
		if(self::$smtp == null)
		{
			require_once __DIR__.'/Smtp.php';
			self::$smtp = new Smtp();
		}
	}
	
	public function send()
	{
		$this->to = (array) $this->to;
		list($tmp, self::$smtp->FromName, self::$smtp->From) = $this->split($this->from);
		foreach($this->to as $user)
		{
			list($tmp, $name, $email) = $this->split($user); 
			self::$smtp->AddAddress($email, $name);			
		}
		self::$smtp->Subject	= $this->subject;
		self::$smtp->Body		= $this->body;
// 		self::$smtp->IsMail();
		self::$smtp->IsSendmail();
// 		self::$smtp->IsQmail();
		self::$smtp->Send();
	}
	
	private function split($str)
	{
		if(preg_match("@(.*)<(.*)>@", $str, $match))
		{
			return $match;
		}
		return array('','','');
	}
}